package com.zyg.demo.adapter;

import android.support.v7.widget.helper.ItemTouchHelper;

import com.chad.library.adapter.base.BaseItemDraggableAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.zyg.demo.R;
import com.zyg.demo.entity.Plugin;
import com.zyg.demo.entity.PluginFolderView;

public class PluginAdapter extends BaseItemDraggableAdapter<Plugin, BaseViewHolder> {


    /**
     * 控制Mirror刚拖拽出来时，延时move
     */
    private boolean canMove = true;

    public PluginAdapter() {
        super(R.layout.plugin_item, null);
    }

    @Override
    protected void convert(BaseViewHolder helper, Plugin item) {
        helper.setText(R.id.tv_plugin, item.name);
        PluginFolderView folder = helper.getView(R.id.iv_plugin);
        folder.setPlugin(item);
    }

    public boolean canMove() {
        return canMove;
    }

    public void setCanMove(boolean canMove) {
        this.canMove = canMove;
    }

    public ItemTouchHelper getItemTouchHelper() {
        return mItemTouchHelper;
    }

    @Override
    public int getItemViewType(int position) {
        Plugin plugin = getItem(position);
        if (plugin != null) {
            return plugin.type;
        }
        return 0;
    }

}
